turbo: set the Thumb bit on code pointers only when compiling for Thumb - #11361
Open
mikeysklar wants to merge 1 commit into
Open
turbo: set the Thumb bit on code pointers only when compiling for Thumb#11361mikeysklar wants to merge 1 commit into
mikeysklar wants to merge 1 commit into
Conversation
On Xtensa and RISC-V, bit 0 makes native calls jump to an odd address. ARM needs it for Thumb. Set it only when __thumb__ is defined. RP2 loads native .mpy with the emitter off, so not MICROPY_EMIT_THUMB. No change on main: no non-ARM port runs native code yet. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
dhalbert
approved these changes
Sep 13, 2026
dhalbert
left a comment
Collaborator
There was a problem hiding this comment.
Thanks - makes sense. A little surprised we didn't hit this before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Turbo needs this to support XTENSA and RISC-V.
Bit 0 is set only when
__thumb__is defined. Other targets get the pointer unchanged.Why
Every native call uses this macro. On Xtensa and RISC-V, bit 0 lands one byte past the code and hard-faults.
MICROPY_MAKE_POINTER_CALLABLEpy/mpconfig.h(p); each port overrides| 1py/circuitpy_mpconfig.h:202, all ports| 1__thumb__, notMICROPY_EMIT_THUMB.mpywith the emitter offMICROPY_ENABLE_NATIVE_CODEorMICROPY_EMIT_INLINE_ASM, which no non-Thumb board enablesHardware tested
Build only. Main at
42af95d52e, GCC 15.2.1, Ubuntu 24.04."e")How I tested it
Built each board at main and at this PR, then compared
firmware.binbyte by byte.Scope
Needed before native
.mpycan run on Espressif. No functional change on any board in main.AI assistance
Claude Code was used.